package com.yupi.springbootinit.controller;

import com.yupi.springbootinit.common.BaseResponse;
import com.yupi.springbootinit.common.ResultUtils;
import com.yupi.springbootinit.manager.SearchFacade;
import com.yupi.springbootinit.model.dto.search.SearchRequest;
import com.yupi.springbootinit.model.vo.SearchVO;
import com.yupi.springbootinit.service.PostService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/search")
public class SearchController {

    @Resource
    private PostService postService;
    @Resource
    private SearchFacade searchFacade;

    @PostMapping(value = "/all")
    public BaseResponse<SearchVO> searchAll(@RequestBody SearchRequest searchRequest, HttpServletRequest request) {
        SearchVO searchVO = searchFacade.searchAll(searchRequest, request);
        return ResultUtils.success(searchVO);
    }

    @GetMapping(value="/get/tip/{keyword}")
    public BaseResponse<List<String>> getSearchSuggestion(@PathVariable String keyword){
        List<String> titleSuggestion = postService.getTitleSuggestion(keyword);
        return ResultUtils.success(titleSuggestion);
    }

}
